package com.Bigbluebook.Service;

import com.Bigbluebook.api.ApiConstants;
import com.Bigbluebook.entity.User;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class UserApiService {
    private UserService userService;
    private Retrofit retrofit;
    private Gson gson;
    public UserApiService() {
        gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
                .create();
        retrofit = new Retrofit.Builder()
                .baseUrl(ApiConstants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
        userService = retrofit.create(UserService.class);
    }

    public void registerUser(User user, Callback<User> callback) {
        Call<User> call = userService.registerUser(user);
        call.enqueue(callback);
    }

    public void loginUser(User user, Callback<User> callback) {
        Call<User> call = userService.loginUser(user);
        call.enqueue(callback);
    }

    public void getUser(int userId, Callback<User> callback) {
        Call<User> call = userService.getUser(userId);
        call.enqueue(callback);
    }

    public void updateUser(int userId, User user, Callback<User> callback) {
        Call<User> call = userService.updateUser(userId, user);
        call.enqueue(callback);
    }

    public void deleteUser(int userId, Callback<Void> callback) {
        Call<Void> call = userService.deleteUser(userId);
        call.enqueue(callback);
    }
}
